package service

import (
	"demos/config"
	"demos/model"
)

// CheckLogin 检查用户名和密码，返回是否通过和角色
func CheckLogin(username, password string) (bool, string) {
	var user model.User
	err := config.DB.Where("username = ?", username).First(&user).Error
	if err != nil {
		return false, ""
	}
	if user.Password != password {
		return false, ""
	}
	return true, user.Role
}

// CheckLoginWithID 检查用户名和密码，返回是否通过、角色和用户ID
func CheckLoginWithID(username, password string) (bool, string, uint) {
	var user model.User
	err := config.DB.Where("username = ?", username).First(&user).Error
	if err != nil {
		return false, "", 0
	}
	if user.Password != password {
		return false, "", 0
	}
	return true, user.Role, user.ID
}
